/****************************************************************
 *  This file created by writerB.php on 05/08/2007 at 20:45:32  *
 ****************************************************************
 *  writerB.php created by Tonk (tonk@ctonk.com) in 2007        *
 ****************************************************************
 *                 General Document Information
 *
 *  File Name: account.cpp
 *  Class Name: Account
 *  Data members: 2
 *  Notes:
 ****************************************************************/

#include <iostream>
#include "account.h"
#include "stringutil.h"



int Account::numAccounts = 0;
int Account::accountIndex = 0;


// Default constructor...
Account::Account() {
	setAccountID( ++accountIndex );
	// Increment the object count...
	numAccounts++;
}

// Additional constructors...
Account::Account( const std::string& name, const std::string& password ) {
	setName( name );
	setPassword( password );
	setAccountID( ++accountIndex );
	// Increment the object count...
	numAccounts++;
}

// Copy constructor (Doesn't change _AccountID)...
Account::Account( const Account& ref ) {
	setAccountID( ++accountIndex );
	setName( ref.getName() );
	setPassword( ref.getPassword() );
	// Increment the object count...
	numAccounts++;
}

// Destructor...
Account::~Account() {
	// Decrement the object count...
	numAccounts--;
}

// Assignment operator (Doesn't change _AccountID)...
Account& Account::operator = ( const Account& ref ) {
	setName( ref.getName() );
	setPassword( ref.getPassword() );
	return *this;
}

// Equality operator (Doesn't compare _AccountID)...
bool Account::operator == ( const Account& ref ) const {
	return	(
		   getName() == ref.getName()
		&& getPassword() == ref.getPassword()
		);
}

// Inequality operator (Doesn't compare _AccountID)...
bool Account::operator != ( const Account& ref ) const {
	return	(
		   getName() != ref.getName()
		&& getPassword() != ref.getPassword()
		);
}

// Less than operator (Compares _AccountID)...
bool Account::operator < ( const Account& ref ) const {
	return ( getAccountID() < ref.getAccountID() );
}

// Greater than operator (Compares _AccountID)...
bool Account::operator > ( const Account& ref ) const {
	return ( getAccountID() > ref.getAccountID() );
}

// Protected Methods...
void Account::setAccountID( const int& AccountID ) { // protected
	_AccountID = AccountID;
	return;
}

// Public accessor methods...
int Account::getAccountID( void ) const { // public
	return _AccountID;
}

void Account::setName( const std::string& name ) { // public
	_name = name;
	return;
}

std::string Account::getName( void ) const { // public
	return _name;
}

void Account::setPassword( const std::string& password ) { // public
	_password = password;
	return;
}

std::string Account::getPassword( void ) const { // public
	return _password;
}

// General methods...

// Static methods...

// Associated operators...
std::ostream& operator << ( std::ostream& write, Account& account ) { // associated
	write << account.getName() << '~' << account.getPassword() << '\n';
	return write;
}

std::ostream& operator << ( std::ostream& write, Account* account ) { // associated
	 return ( write << *account );
}

std::istream& operator >> ( std::istream& read, Account& account ) { // associated
	std::string name, password;
	getline( read, name, '~' );
	getline( read, password );
	account.setName( name );
	account.setPassword( password );
	return read;
}

std::istream& operator >> ( std::istream& read, Account* account ) { // associated
	 return ( read >> *account );
}
